package com.itxx.keyCase.demo1;

import java.text.Collator;
import java.util.Locale;

public class Student implements Comparable<Student> {
    private String naem;
    private Integer age;
    private Integer sorce;

    @Override
    public String toString() {
        return "Student{" +
                "naem='" + naem + '\'' +
                ", age=" + age +
                ", sorce=" + sorce +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        if (naem != null ? !naem.equals(student.naem) : student.naem != null) return false;
        if (age != null ? !age.equals(student.age) : student.age != null) return false;
        return sorce != null ? sorce.equals(student.sorce) : student.sorce == null;
    }

    @Override
    public int hashCode() {
        int result = naem != null ? naem.hashCode() : 0;
        result = 31 * result + (age != null ? age.hashCode() : 0);
        result = 31 * result + (sorce != null ? sorce.hashCode() : 0);
        return result;
    }

    public String getNaem() {
        return naem;
    }

    public void setNaem(String naem) {
        this.naem = naem;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Integer getSorce() {
        return sorce;
    }

    public void setSorce(Integer sorce) {
        this.sorce = sorce;
    }

    public Student(String naem, Integer age, Integer sorce) {
        this.naem = naem;
        this.age = age;
        this.sorce = sorce;
    }

    public Student() {
    }


    @Override
    public int compareTo(Student o) {
        //主要条件是 年龄
        int result = this.age - o.age;
        //次要条件 成绩
        if (result == 0) {
            result = this.sorce - o.sorce;
        }
        //次要条件 名字首字母
        if (result == 0) {
            Collator instance = Collator.getInstance(Locale.CHINA);
             result = instance.compare(this.naem, o.naem);
        }
        return result;
    }
}
